import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class ListenerThread extends Thread {
	private Socket socket = null;
	private InetAddress ip;

	public ListenerThread(Socket socket, InetAddress inetAddress) {
		super("ListenerThread");
		this.socket = socket;
		this.ip = inetAddress;
	}

	public void run() {
		System.out.println("Starting Listener Thread");
		try {
			PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
			BufferedReader in = new BufferedReader(
					new InputStreamReader(
							socket.getInputStream()));

			String inputLine;
			
			inputLine = in.readLine();
			System.out.println("Listener "+ip.getHostAddress()+" received: "+inputLine);	
			
			System.out.println(ip.getHostAddress()+" responding to call");
			out.println("This is listener "+ip.getHostAddress()+" responding to call");

			out.close();
			in.close();
			socket.close();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}